package com.test.runable;

import com.test.manage.ThreadManager;
import com.test.pojo.DataEntity;
import com.test.pojo.DataState;

public class Task {
    /**
     * 进入到下一个状态
     *
     * @param dataEntity dataEntity
     */
    private void increaseDataEntityState(DataEntity dataEntity) {
        DataState nextState = DataState.getStateByCode(dataEntity.getState().getCode() + 1);
        if (nextState != null) {
            dataEntity.setState(nextState);
            ThreadManager.offerQueue(dataEntity);
        }
    }

    /**
     * 执行任务，消费一定的时间
     *
     * @param seconds 消费的时间
     */
    protected void doSomethingForCertainTime(final DataEntity dataEntity, final int seconds) {
        try {
            dataEntity.setValue(dataEntity.getValue() + seconds);
            increaseDataEntityState(dataEntity);
            Thread.sleep(seconds * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
